package com.hhsj.dynamicui.server.server;


import com.hhsj.androidserver.HttpServer;

/**
 * 监听线程
 */
public class ListenThread extends Thread {

    private HttpServer httpServer;

    public ListenThread(int port) {
        super("HttpServerThread");
        try {
            httpServer = HttpServer.create().port(port);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        try {
            httpServer.start();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("HttpServer start " + e.getLocalizedMessage());
        }
    }

    public void shutDown() {
        if (httpServer != null) {
            try {
                httpServer.stop();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("HttpServer shutDown " + e.getLocalizedMessage());
            }
            httpServer = null;
        }
    }


}